/*
db.exec("select * from go_user2 where id=?",[156],function(err,r){
    console.log(err,r);
});
 */
var mysql = require('mysql');
var settings = require('../settings');
var option = {
    host: settings.db.host,
    port: settings.db.port,
    user: settings.db.user,
    password: settings.db.password,
    database: settings.db.database
};

function _exec(sqls, values, after) {
    var client = mysql.createConnection(option);
    client.connect(function(err) {
        if (err) {
            console.log(err);
            return;
        }
        client.query(sqls || '', values || [], function(err, r) {
            after(err, r);
        });
        client.end();
    });
    client.on('error', function(err) {
        if (err.errno != 'ECONNRESET') {
            after("err01", false);
            throw err;
        } else {
            after("err02", false);
        }
    });
}
exports.exec = _exec;